package com.byxy.action;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.byxy.entity.User;
import com.byxy.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class RePassword extends ActionSupport {
	@Resource
	private UserService userService;
	private String oldpassword;
	private String newpassword;
	private String rnewpassword;
		
	
	public String getOldpassword() {
		return oldpassword;
	}

	public void setOldpassword(String oldpassword) {
		this.oldpassword = oldpassword;
	}

	public String getNewpassword() {
		return newpassword;
	}

	public void setNewpassword(String newpassword) {
		this.newpassword = newpassword;
	}

	public String getRnewpassword() {
		return rnewpassword;
	}

	public void setRnewpassword(String rnewpassword) {
		this.rnewpassword = rnewpassword;
	}

	public String passwordchange() {
		if(ServletActionContext.getRequest().getMethod().equalsIgnoreCase("post")) {
			
			User user = (User)ServletActionContext.getRequest().getSession().getAttribute("user");
			user=userService.get(user.getId());
			if(oldpassword.equals(user.getPassword())) {
				if(newpassword.equals(rnewpassword)) {
					user.setPassword(newpassword);
					userService.update(user);
					return SUCCESS;
				}
			}
				
					
			}
		
		return "passwordchange";
	}
		
}
		
